set scheme lean2

********************Main Text*************************



*****Figure 1*****
sort xgwf_casename year
collapse (sum) gwf_personal gwf_party gwf_monarch gwf_military, by(year)

sort year
twoway (line gwf_personal year,sort lcolor(black) lwidth(med)) (line gwf_party year,sort lcolor(black) lpattern(dash)) ///
(line gwf_military year,sort lcolor(black) lpattern(vshortdash)) (line gwf_monarch year,sort lcolor(black) lpattern(dot)), ///
legend(label(1 "Personalist") label(2 "Single-party") label(3 "Military") label(4 "Monarchy") size(medsmall) pos(6) row(1)) ///
xtitle("Year") ytitle("Autocratic regime cases") xlab(1950(10)2010,nogrid) ylab(,nogrid) scheme(lean2)


*****Table 1*****
irt 2pl officepers milmerit_pers sectyapp_pers milnotrial paramil_pers 
estat report, byparm sort(a)

*generate security forces personalization measure
predict xpers_pl, latent se(xpers_se_pl)
sum xpers_pl
gen xpers =(xpers_pl+abs(r(min)))/(abs(r(min)) + r(max))
hist xpers

*****Figure 1*****
*gen alpha = discrimination
gen a_milnotrial = 0
gen a_milmeritpers = 0
gen a_officepers = 0
gen a_paramilpers = 0
gen a_sectyapppers = 0

recode a_milnotrial (0= 1.354858)
recode a_milmeritpers (0= 1.430053)
recode a_officepers (0= 1.721821)
recode a_paramilpers (0= 1.941585)
recode a_sectyapppers (0= 3.460844)

*gen beta = difficulty
gen b_milnotrial = 0
gen b_milmeritpers = 0
gen b_officepers = 0
gen b_paramilpers = 0
gen b_sectyapppers = 0

recode b_milnotrial (0= .5498592)
recode b_milmeritpers (0= -1.110888)
recode b_officepers (0= -.5269312)
recode b_paramilpers (0= .4979904)
recode b_sectyapppers (0= -.2878343)

*gen inflection point = -(beta/alpha)
gen inf_officepers = -(b_officepers/a_officepers)
gen inf_paramilpers = -(b_paramilpers/a_paramilpers)
gen inf_sectyapppers  = -(b_sectyapppers/a_sectyapppers)
gen inf_milmeritpers = -(b_milmeritpers/a_milmeritpers)
gen inf_milnotrial = -(b_milnotrial/a_milnotrial)

irtgraph icc officepers, blocation /*-0.527*/
irtgraph icc officepers, lcolor(gray) lwidth(medthick) xline(-0.527, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal appointment") saving(if_officepers, replace)

irtgraph icc paramil_pers, blocation /*0.498*/
irtgraph icc paramil_pers, lcolor(gray) lwidth(medthick) xline(0.498, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal paramilitary") saving(if_paramilpers, replace)

irtgraph icc sectyapp_pers, blocation /*-0.288*/
irtgraph icc sectyapp_pers, lcolor(gray) lwidth(medthick) xline(-0.288, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal control") saving(if_sectyapppers, replace)

irtgraph icc milmerit_pers, blocation /*-1.11*/
irtgraph icc milmerit_pers, lcolor(gray) lwidth(medthick) xline(-1.11, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal promotion") saving(if_milmeritpers, replace)

irtgraph icc milnotrial, blocation /*0.55*/
irtgraph icc milnotrial, lcolor(gray) lwidth(medthick) xline(0.55, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal purge") saving(if_milnotrial, replace)

graph combine if_officepers.gph if_paramilpers.gph if_sectyapppers.gph if_milmeritpers.gph if_milnotrial.gph, col(3) 

*****Table 2*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_binary xpers coupyrs coupyrs2 coupyrs3 $dec, cluster(xgwf_caseid) fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers coupyrs coupyrs2 coupyrs3 $dec, group(xgwf_caseid) cluster(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using Main-Table2.tex, b(3) se ar2 

*****Figure 3*****
eststo clear
global dec ="d196 d197 d198 d199 d200"
tsset xgwf_caseid year
xtreg coup_binary xpers $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)

margins, at(xpers=(0(0.2)1)) atmeans
marginsplot, xtitle("Personalization level") ytitle("Marginal Effect of {it:Personalization level}") title("") yline(0, lcolor(red) lpattern(solid)) xlab(,nogrid axis(1)) ylab(,nogrid) saving(LPM.gph, replace) ///
scheme(lean2) recast(line) plotopts(lcolor(gs5) lpattern(solid) lwidth(medthick)) recastci(rline) ciopts(lcolor(gs10) lpattern(dash))

*****Figure 4*****
*generate personalization timing
sort xgwf_caseid year

by xgwf_caseid: gen Dxpers=xpers-l.xpers
replace Dxpers=0 if Dxpers==.

gen xpersplus =0
replace xpersplus=1 if Dxpers>0

by xgwf_caseid: gen xpersplusT = xpersplus[_n+1]
by xgwf_caseid: gen xpersplusT_1 = xpersplus[_n+2]
by xgwf_caseid: gen xpersplus1 = xpersplus[_n-1]

replace xpersplusT=0 if xpersplusT==.
replace xpersplusT_1=0 if xpersplusT_1==.
replace xpersplus1=0 if xpersplus1==.

*collapse from main dataset (bar graph)
gen changetype4=.
replace changetype4=1 if xpersplusT_1==1
replace changetype4=2 if xpersplusT==1
replace changetype4=3 if xpersplus==1
replace changetype4=4 if xpersplus1

collapse (mean) meancoup_binary=coup_binary meancoup_succ=coup_succ (sd) sdcoup_binary=coup_binary sdcoup_succ=coup_succ (count) attN=coup_binary succN=coup_succ, by(changetype4)

*create CI for coup attempt
generate hiatt = meancoup_binary + invttail(attN-1,0.025)*(sdcoup_binary / sqrt(attN))
generate lowatt = meancoup_binary - invttail(attN-1,0.025)*(sdcoup_binary / sqrt(attN))

*create CI for coup success
generate hisucc = meancoup_succ + invttail(succN-1,0.025)*(sdcoup_succ / sqrt(succN))
generate lowsucc = meancoup_succ - invttail(succN-1,0.025)*(sdcoup_succ / sqrt(succN))

gen stratt=""
gen strsucc=""

gen attpercent = meancoup_binary*100
gen succpercent = meancoup_succ*100

graph twoway (bar meancoup_binary changetype4, bcolor(gs9) lcolor(none)) (rcap hiatt lowatt changetype4, lcolor(red)) , ///
xlabel(1 "{it:t-}1" 2 "{it:t}" 3 "{it:t+}1" 4 "{it:t+}2") ylabel(0 "0" .05 "5" .10 "10" .15 "15" .20 "20" .25 "25",nogrid) ///
legend(cols(2) label(1 "Coup attempt=1") label(2 "95% CI") position(6)) name(CI1, replace) nodraw xtitle("Personalization timing") ytitle("Baseline coup attempt risk") title("Coup attempt") ///
|| scatter meancoup_binary changetype4, mlabel(stratt) mlabsize(medium) mlabpos(2) ms(none) legend(off) saving(ci1, replace) scheme(lean2)

graph twoway (bar meancoup_succ changetype4, bcolor(gs5) lcolor(gs5)) (rcap hisucc lowsucc changetype4, lcolor(red)) , ///
 xlabel(1 "{it:t-}1" 2 "{it:t}" 3 "{it:t+}1" 4 "{it:t+}2") ylabel(0 "0" .05 "5" .10 "10" .15 "15" .20 "20" .25 "25",nogrid)  ///
legend(cols(2) label(1 "Coup success=1") label(2 "95% CI") position(6)) name(CI2, replace) nodraw xtitle("Personalization timing") ytitle("Baseline coup success risk") title("Coup success") ///
|| scatter meancoup_succ changetype4, mlabel(strsucc) mlabsize(medium) mlabpos(2) ms(none) legend(off) saving(ci2, replace) scheme(lean2)
 
graph combine ci1.gph ci2.gph,  col(2) xsize(6) ysize(4) 



********************Appendix A*************************



*****Appendix Table 1*****
irt 2pl officepers milmerit_pers sectyapp_pers milnotrial paramil_pers 
estat report, byparm sort(a)

*generate security forces personalization measure
predict xpers_pl, latent se(xpers_se_pl)
sum xpers_pl
gen xpers =(xpers_pl+abs(r(min)))/(abs(r(min)) + r(max))
hist xpers

*****Appendix Figure 1*****
*calculate percentages
egen caseid = group(gwf_casename)
egen countryid = group(xgwf_country)
egen cowcount = group(cowcode)

gen freq=1
			
	graph bar (count) freq, over(paramil_pers, relabel(1 "No" 2 "Yes") gap(5)) bar(1, fcolor(white) lwidth(medium)) plotregion(margin(b = 1)) ///
		blabel(bar, position(outside) size(medium))  ytitle("Count") subtitle("Personal paramilitary") ylabel(,nogrid) name(b1, replace) nodraw
	graph bar (count) freq, over(sectyapp_pers, relabel(1 "No" 2 "Yes") gap(5)) bar(1, fcolor(white) lwidth(medium)) plotregion(margin(b = 1)) ///
		blabel(bar, position(outside) size(medium))  ytitle("Count") subtitle("Personal control") ylabel(,nogrid) name(b2, replace) nodraw
	graph bar (count) freq, over(milmerit_pers, relabel(1 "No" 2 "Yes") gap(5)) bar(1, fcolor(white) lwidth(medium)) plotregion(margin(b = 1)) ///
		blabel(bar, position(outside) size(medium))  ytitle("Count") subtitle("Personal promotion") ylabel(,nogrid) name(b3, replace) nodraw
	graph bar (count) freq, over(milnotrial, relabel(1 "No" 2 "Yes") gap(5)) bar(1, fcolor(white) lwidth(medium)) plotregion(margin(b = 1)) ///
		blabel(bar, position(outside) size(medium))  ytitle("Count") subtitle("Personal purge") ylabel(,nogrid) name(b4, replace) nodraw
	graph bar (count) freq, over(officepers, relabel(1 "No" 2 "Yes") gap(5)) bar(1, fcolor(white) lwidth(medium)) plotregion(margin(b = 1)) ///
		blabel(bar, position(outside) size(medium))  ytitle("Count") subtitle("Personal appointment") ylabel(,nogrid) name(b5, replace) nodraw
	graph bar (count) freq, over(gwf_personal, relabel(1 "No" 2 "Yes") gap(5)) bar(1, fcolor(white) lwidth(medium)) plotregion(margin(b = 1)) ///
		blabel(bar, position(outside) size(medium))  ytitle("Count") subtitle("GWF personal regime") ylabel(,nogrid) name(b6, replace) nodraw

graph combine b1 b2 b3 b4 b5 b6, col(3) ycommon iscale(*.8) xsize(5) ysize(4)

*use CategoryBar.dta (manually constructed)
graph bar (mean) Yes No, over(variable, gap(75) sort(order) relabel(2 `""Categorical" "Regime""')) percentage stack blabel(bar, position(inside) format(%9.1f)) ///
legend(label(1 "Positive (1) observations") label(2 "Non-positive (0) observations") position(6) col(2)) ytitle("Percent") 

*****Appendix Figure 2*****
*gen alpha = discrimination
gen a_milnotrial = 0
gen a_milmeritpers = 0
gen a_officepers = 0
gen a_paramilpers = 0
gen a_sectyapppers = 0

recode a_milnotrial (0= 1.354858)
recode a_milmeritpers (0= 1.430053)
recode a_officepers (0= 1.721821)
recode a_paramilpers (0= 1.941585)
recode a_sectyapppers (0= 3.460844)

*gen beta = difficulty
gen b_milnotrial = 0
gen b_milmeritpers = 0
gen b_officepers = 0
gen b_paramilpers = 0
gen b_sectyapppers = 0

recode b_milnotrial (0= .5498592)
recode b_milmeritpers (0= -1.110888)
recode b_officepers (0= -.5269312)
recode b_paramilpers (0= .4979904)
recode b_sectyapppers (0= -.2878343)

*gen inflection point = -(beta/alpha)
gen inf_officepers = -(b_officepers/a_officepers)
gen inf_paramilpers = -(b_paramilpers/a_paramilpers)
gen inf_sectyapppers  = -(b_sectyapppers/a_sectyapppers)
gen inf_milmeritpers = -(b_milmeritpers/a_milmeritpers)
gen inf_milnotrial = -(b_milnotrial/a_milnotrial)

irtgraph icc officepers, blocation /*-0.527*/
irtgraph icc officepers, lcolor(gray) lwidth(medthick) xline(-0.527, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal appointment") saving(if_officepers, replace)

irtgraph icc paramil_pers, blocation /*0.498*/
irtgraph icc paramil_pers, lcolor(gray) lwidth(medthick) xline(0.498, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal paramilitary") saving(if_paramilpers, replace)

irtgraph icc sectyapp_pers, blocation /*-0.288*/
irtgraph icc sectyapp_pers, lcolor(gray) lwidth(medthick) xline(-0.288, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal control") saving(if_sectyapppers, replace)

irtgraph icc milmerit_pers, blocation /*-1.11*/
irtgraph icc milmerit_pers, lcolor(gray) lwidth(medthick) xline(-1.11, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal promotion") saving(if_milmeritpers, replace)

irtgraph icc milnotrial, blocation /*0.55*/
irtgraph icc milnotrial, lcolor(gray) lwidth(medthick) xline(0.55, lcolor(red)) yline(0.5) ylab(,nogrid) title("Personal purge") saving(if_milnotrial, replace)

graph combine if_officepers.gph if_paramilpers.gph if_sectyapppers.gph if_milmeritpers.gph if_milnotrial.gph, col(3) 

*****Appendix Figure 3*****
*stadardize the effective number of ground combat units data
egen min = min(effective)
egen max = max(effective)
gen stdeffective = (effective - min) / (max - min) 

*Soviet Union/Russia
twoway (line xpers year if cowcode==365,sort lcolor(blue) ylabel(0 "Min" 1 "Max",glcolor(gs16)) saving(Russia.gph,replace)) ///
(line stdeffective year if cowcode==365, legend(label(1 "Personalization index") label(2 "Effective number") pos(6) row(1)) ///
scheme(lean2) yaxis(1) xlab(1950(10)2010) xtitle(Year) ytitle("",axis(1)) sort mcolor(red) title("Soviet Union/Russia") cmissing(n))
				
*China
twoway (line xpers year if cowcode==710,sort lcolor(blue) ylabel(0 "Min" 1 "Max",glcolor(gs16)) saving(China.gph,replace)) ///
(line stdeffective year if cowcode==710, legend(off) scheme(lean2) yaxis(1) ///
xlab(1950(10)2010) xtitle(Year) ytitle("",axis(1)) sort mcolor(red) title("China") cmissing(n))	
				
*Syria
twoway (line xpers year if xgwf_country=="Syria",sort lcolor(blue) ylabel(0 "Min" 1 "Max",glcolor(gs16)) saving(Syria.gph,replace)) ///
(line stdeffective  year if xgwf_country=="Syria",legend(off) scheme(lean2) yaxis(1) ///
xlab(1950(10)2010) xtitle(Year) ytitle("",axis(1)) sort mcolor(red) title("Syria"))
			
*Ghana
twoway (line xpers year if xgwf_country=="Ghana",sort lcolor(blue) ylabel(0 "Min" 1 "Max",glcolor(gs16)) saving(Ghana.gph,replace)) ///
(line stdeffective  year if xgwf_country=="Ghana",legend(off) yaxis(1) scheme(lean2) ///
xlab(1950(10)2010) xtitle(Year) ytitle("",axis(1)) sort mcolor(red) title("Ghana"))

*combine
set scheme lean2
grc1leg Russia.gph China.gph Syria.gph Ghana.gph, legendfrom(Russia.gph) ///
col(2) ycommon fxsize(500) fysize(500) iscale(*0.8) 



********************Appendix B*************************



*****Appendix Figure 4***** (use AVP_base.dta and AVP.do)
reg loguntil logtenure loggdp coldwar xpers, vce(cluster gwf_casename)
avplot xpers, plotregion(lcolor(none) ilcolor(none) style(none)) mcolor(gs10) msize(medsmall) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) scheme(lean2) ylabel(-8(4)8,nogrid) xlabel(-0.6(0.2)0.6) ///
rlopts(lpattern(solid) lcolor(red)) xtitle("e(Personalization index|X)") ytitle("e(Days until coup attempt (logged)|X )")

*****Appendix Figure 5*****
gen mpers = milmerit_pers + milnotrial + sectyapp_pers + paramil_pers + officepers
tab mpers

xtset xgwf_leaderid year
gen dmpers=d.mpers
tab dmpers

replace dmpers=0 if dmpers<0 & dmpers~=.
replace dmpers=1 if dmpers>=1 & dmpers~=.

egen meanpers = mean(dmpers) if mpers~=5, by(xgwf_leader_duration)

egen meanpersmyway = mean(dmpers), by(xgwf_leader_duration)

twoway line meanpers xgwf_leader_duration if xgwf_leader_duration<=50, ///
sort ytitle("Probability of increasing personalization") scheme(lean2) ylabel(,nogrid glcolor(gs16)) xlabel(,glcolor(gs16)) lpattern(dash)



********************Appendix C*************************



*****Appendix Table 2*****
pwcorr paramil_pers sectyapp_pers milmerit_pers milnotrial officepers xpers

*****Appendix Figure 6***** (use Variance_new.dta, manually constructed)
tsset xgwf_caseid year
xtsum coup_binary gwf_personal xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil leffective

*calculate between- and within-variances
replace BetweenV = BetweenSD^2
replace WithinV= WithinSD^2
gen TotalV=.
replace TotalV = BetweenV+WithinV
replace Ratio = BetweenV/TotalV
gen Ratio2=.
replace Ratio2 = WithinV/TotalV

generate pos = 3
replace pos =9 if variable=="Coup attempt"
replace pos =12 if variable=="GDP/k"

twoway scatter Ratio2 TotalV, mc() mlabel(variable) msymbol(smcircle) mlabv(pos)  ///
ytitle("Within Variance/Total Variance") xtitle("Total Variance") legend(off) yline(0.50, lpattern(dash) lcolor(red) lwidth(thin)) ///
ylabel(-0.1(0.1)0.6) xlabel(-4(1)9) ylabel(,nogrid) scheme(lean2)

*****Appendix Figure 7*****
sum xpers effective_number counterbal paramilitary
mdesc xpers effective_number counterbal paramilitary

misstable sum, generate(miss_)
describe miss_*

gen miss_xpers=0

gen nonmiss_xpers=1
gen nonmiss_effective=miss_effective_number
gen nonmiss_counterbal=miss_counterbal
gen nonmiss_paramil=miss_paramilitary

replace nonmiss_effective=1 if miss_effective==0
replace nonmiss_effective=0 if miss_effective==1
replace nonmiss_counterbal=1 if miss_counterbal==0
replace nonmiss_counterbal=0 if miss_counterbal==1
replace nonmiss_paramil=1 if miss_paramil==0
replace nonmiss_paramil=0 if miss_paramil==1

collapse (mean) nonmiss_xpers nonmiss_effective nonmiss_counterbal nonmiss_para, by(year)

twoway (line nonmiss_xpers year,sort lcolor(blue) lwidth(medthick) lpattern())  ///
	(line nonmiss_effective year,sort lcolor(black) lwidth(medthick) lpattern()) ///
	,legend(on position(6) col(2) label(1 "Personalization level") label(2 "Effective number")) ///
	scheme(lean2) ylab(,glcolor(gs16)) ytitle("% of non-missing observations",axis(1)) ///
	xlab(1950(10)2010) xtitle(Year) ylab(0 "0" .2 "20" .4 "40" .6 "60" .8 "80" 1 "100")

*****Appendix Figure 8*****
*line for personalization level
egen m_xpers = mean(xpers), by(year)

twoway line m_xpers year, ///
sort scheme(lean2) ylabel(,nogrid glcolor(gs16)) xlabel(,glcolor(gs16)) lpattern(solid) ///
xlab(1950(10)2010) xtitle("Year") ytitle("IRT Personalization level (annual average)") saving(lineIRT,replace)

*histogram for personalization level
hist xpers, ylabel(,nogrid glcolor(gs16)) xlabel(,glcolor(gs16)) xtitle("IRT Personalization level") ///
saving(histIRT,replace)

*****Appendix Table 3*****
sum coup_binary lmilexp lmilper loggdp logoil milethnic_homo ucdp25 ucdp1000 navcoV navcoNV coldwar leadermil coupyrs

*****Appendix Table 4 & 5*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year
stset coupyrs, fail(coup_binary)

*no strata, no fix
eststo: stcox $dec xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil, ///
	nohr cluster(xgwf_caseid)
stphtest,detail
sum year if e(sample)==1
tab coup_binary if e(sample)==1

*yes strata, no fix
eststo: stcox $dec xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil, ///
	nohr cluster(xgwf_caseid) strata(xgwf_caseid)
stphtest,detail /*Apppendix Table 5*/
sum year if e(sample)==1
tab coup_binary if e(sample)==1

*no strata, yes fix
eststo: stcox $dec xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil, ///
	nohr cluster(xgwf_caseid) tvc(d1960 d2000 xpers loggdp logoil lnavcoV lnavcoNV) texp(log(_t))
sum year if e(sample)==1
tab coup_binary if e(sample)==1

*yes strata, yes fix
eststo: stcox $dec xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil, ///
	nohr cluster(xgwf_caseid) strata(xgwf_caseid) tvc(lmilexp loggdp) texp(log(_t))
sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using Appendix-Table4.tex, b(3) se ar2 

*****Appendix Table 6*****
*generate personalization timing
sort xgwf_caseid year

by xgwf_caseid: gen Dxpers=xpers-l.xpers
replace Dxpers=0 if Dxpers==.

gen xpersplus =0
replace xpersplus=1 if Dxpers>0

by xgwf_caseid: gen xpersplusT = xpersplus[_n+1]
by xgwf_caseid: gen xpersplusT_1 = xpersplus[_n+2]
by xgwf_caseid: gen xpersplus1 = xpersplus[_n-1]

replace xpersplusT=0 if xpersplusT==.
replace xpersplusT_1=0 if xpersplusT_1==.
replace xpersplus1=0 if xpersplus1==.

*run models
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 coupyrs coupyrs2 coupyrs3 $dec, ///
	cluster(xgwf_caseid) fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 coupyrs coupyrs2 coupyrs3 $dec, ///
	group(xgwf_caseid) cluster(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 $dec ///
	lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 $dec ///
	lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 $dec ///
	lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 $dec ///
	lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 ///
	lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpersplusT_1 xpersplusT xpersplus xpersplus1 ///
	lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using Appendix-Table6.tex, b(3) se ar2 

*****Appendix Table 7*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_succ xpers coupyrs coupyrs2 coupyrs3 $dec if coup_binary==1, cluster(xgwf_caseid) fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_succ xpers coupyrs coupyrs2 coupyrs3 $dec if coup_binary==1, group(xgwf_caseid) cluster(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_succ xpers $dec lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3 if coup_binary==1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_succ xpers $dec lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3 if coup_binary==1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_succ xpers $dec lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3 if coup_binary==1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_succ xpers $dec lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3 if coup_binary==1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_succ xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3 if coup_binary==1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_succ xpers lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3 if coup_binary==1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable7.tex, b(3) se ar2 

*****Appendix Table 8*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_succ xpers coupyrs coupyrs2 coupyrs3 $dec if coup_binary==1, cluster(xgwf_caseid) fe i(xgwf_caseid)
 sum year if e(sample)==1

eststo: clogit coup_succ xpers coupyrs coupyrs2 coupyrs3 $dec if coup_binary==1, group(xgwf_caseid) cluster(xgwf_caseid)
sum year if e(sample)==1

eststo: xtreg coup_succ xpersplusT_1 xpersplusT xpersplus xpersplus1 coupyrs coupyrs2 coupyrs3 $dec if coup_binary==1, cluster(xgwf_caseid) fe i(xgwf_caseid)
 sum year if e(sample)==1

eststo: clogit coup_succ xpersplusT_1 xpersplusT xpersplus xpersplus1 coupyrs coupyrs2 coupyrs3 $dec if coup_binary==1, group(xgwf_caseid) cluster(xgwf_caseid)
sum year if e(sample)==1

esttab using AppendixTable8.tex, b(3) se ar2 

*****Appendix Figure 9*****
*use Nonstdpers.dta and Uncertainty.R to construct sim1000.csv

*Create uncertainty test dataset
sort cowcode year
browse cowcode year coup_binary xgwf_caseid xpers d1960 d1970 d1980 d1990 d2000 lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3
keep cowcode year coup_binary xgwf_caseid xpers d1960 d1970 d1980 d1990 d2000 lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3
*save as TrimmedMain.dta
clear

global r = 1000
set matsize 1500
insheet using "sim1000.csv" 
recode cow (679=678)
sort cowcode year
drop if year==year[_n-1] & cow==cow[_n-1]
sort cowcode year
merge m:m cowcode year using TrimmedMain, /* merge with main data */
tab _merge
*save as Uncertainty.dta

*OLS test
set matsize 1500
global r = 1000
	*use Uncertainty, clear
	global dec ="d196 d197 d198 d199 d200"
	global cvar = "lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3"
	matrix sims = J($r,1,.)
	xtset xgwf_caseid year
	xtreg coup_binary sim1 $dec $cvar, cluster(xgwf_caseid) fe i(xgwf_caseid)
	keep if e(sample)
	forvalues i = 1(1)$r {
		qui: xtreg coup_binary sim`i' $dec $cvar, cluster(xgwf_caseid)fe i(xgwf_caseid)
		nlcom _b[sim`i'], post level(95)
		matrix sims[`i',1]= e(b)
	}


clear
set obs $r
gen l=.
gen u=.
gen e=.
local t = 1

	qui gen personalOLS =.
	forvalues i = 1(1)$r { 
		local z = sims[`i',1]
		qui replace personalOLS=`z' if _n==`i'
	}

*Conditional logit test
set matsize 1500
global r = 1000
	*use Uncertainty, clear
	global dec ="d196 d197 d198 d199 d200"
	global cvar = "lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3"
	matrix sims = J($r,1,.)
	xtset xgwf_caseid year
	clogit coup_binary sim1 $dec $cvar, cluster(xgwf_caseid) group(xgwf_caseid)
	keep if e(sample)
	forvalues i = 1(1)$r {
		qui: clogit coup_binary sim`i' $dec $cvar, cluster(xgwf_caseid) group(xgwf_caseid)
		nlcom _b[sim`i'], post level(95)
		matrix sims[`i',1]= e(b)
	}


clear
set obs $r
gen l=.
gen u=.
gen e=.
local t = 1

	qui gen personalLogit =.
	forvalues i = 1(1)$r { 
		local z = sims[`i',1]
		qui replace personalLogit=`z' if _n==`i'
	}

*Stratified cox test
set matsize 1500
global r = 1000
	*use Uncertainty, clear
	global dec ="d196 d197 d198 d199 d200"
	global cvar = "lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil" /* no coupyrs for stcox */
	matrix sims = J($r,1,.)
	xtset xgwf_caseid year
	stset coupyrs, fail(coup_binary)
	stcox sim1 $dec $cvar, nohr cluster(xgwf_caseid) strata(xgwf_caseid) tvc(lmilexp loggdp) texp(log(_t))
	keep if e(sample)
	forvalues i = 1(1)$r {
		qui: stcox sim`i' $dec $cvar, nohr cluster(xgwf_caseid) strata(xgwf_caseid) tvc(lmilexp loggdp) texp(log(_t))
		nlcom _b[sim`i'], post level(95)
		matrix sims[`i',1]= e(b)
	}


clear
set obs $r
gen l=.
gen u=.
gen e=.
local t = 1

	qui gen personalCox =.
	forvalues i = 1(1)$r { 
		local z = sims[`i',1]
		qui replace personalCox=`z' if _n==`i'
	}

*Graphs
egen plow = pctile(personalOLS), p(2.5)
egen phigh = pctile(personalOLS), p(97.5)
sum plow phigh
hist personalOLS, freq normal normopts(lcolor(red)) xtitle("Estimated Personalization Index Coefficients for OLS") ///
xline(-.022059 -.0034143, lpattern(dash) lcolor(blue)) ylabel(,nogrid) scheme(lean2) /* calculate 95% CI manually */

egen plow = pctile(personalLogit), p(2.5)
egen phigh = pctile(personalLogit), p(97.5)
sum plow phigh
hist personalLogit, freq normal normopts(lcolor(red)) xtitle("Estimated Personalization Index Coefficients for Conditional Logit") ///
xline(-.4908947 -.1010234 , lpattern(dash) lcolor(blue)) ylabel(,nogrid) scheme(lean2)

egen plow = pctile(personalCox), p(2.5)
egen phigh = pctile(personalCox), p(97.5)
sum plow phigh
hist personalCox, freq normal normopts(lcolor(red)) xtitle("Estimated Personalization Index Coefficients for Stratified Cox") ///
xline(-.7058927 -.2016768, lpattern(dash) lcolor(blue)) ylabel(,nogrid) scheme(lean2)


graph combine personalOLS.gph personalLogit.gph personalCox.gph,col(1) iscale(*.8) xsize(8) ysize(12)

*****Appendix Figure 10*****
eststo clear
global dec ="d196 d197 d198 d199 d200"
*OLS: model 5
eststo: xtreg coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 navcoV navcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
estimates store OLS
*Logit: model 6
eststo: clogit coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 navcoV navcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
estimates store Logit
*Survival: model 11 (corrected version)
stset coupyrs, fail(coup_binary)
eststo: stcox $dec xpers lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil, nohr cluster(xgwf_caseid) tvc(lmilexp loggdp) texp(log(_t))
estimates store Cox

coefplot OLS Logit Cox, bylabel(Personalization index) ||, keep(xpers) coeflabel(xpers = `""Personalization" "level""') scheme(lean2) ///
xline(0, lcolor(red) lpattern(dash)) norecycle byopts(xrescale) legend(rows(1) position(6)) ///
ciopts(recast(rcap) lpattern(dash) color(gs10)) mcolor(black) xsize(6) ysize(4) 

*****Appendix Table 9*****
irt 2pl officepers milmerit_pers sectyapp_pers milnotrial paramil_pers milethnic_homo
estat report, byparm sort(a)

*****Appendix Figure 11*****
irtgraph icc (paramil_pers, lcolor(green)) (sectyapp_pers, lcolor(red)) (milmerit_pers, lcolor(gold) blocation(lcolor(gold) lwidth(vthin) lpattern(solid))) ///
(milnotrial, lcolor(gray)) (officepers, lcolor(blue)) (milethnic_homo, lcolor(black) lpattern(dash) blocation(lcolor(black) lwidth(vthin) lpattern(dash))), ///
legend(col(3) size(vsmall) position(6) ///
order(1 "Personal paramilitary" 2 "Personal control" 3 "Personal promotion" 4 "Personal purge" 5 "Personal appointment" 6 "Homogenous ethnic military")) ///
xsize(6) ysize(5) scheme(lean2) ylabel(0(0.25)1,nogrid) yline(0.5, lpattern(solid) lcolor(gs12) lwidth(vthin)) xtitle("Difficulty")


*****Appendix Figure 12*****
*PCA without milethnic_homo
pca officepers milmerit_pers sectyapp_pers milnotrial paramil_pers
rotate

scree, yline(1, lpattern(solid) lcolor(gs12) lwidth()) scheme(lean2) ylabel(,nogrid) legend(off) saving(pca1.gph, replace) ///
lcolor(black) lpattern(solid) lwidth(medthick) msymbol(circle) mcolor(black) msize(medlarge) title("No {it:Homogenous Ethnic Military}") xtitle("Components") 

*PCA with
pca officepers milmerit_pers sectyapp_pers milnotrial paramil_pers milethnic_homo
rotate
scree, yline(1, lpattern(solid) lcolor(gs12) lwidth()) scheme(lean2) ylabel(,nogrid) legend(off) saving(pca2.gph, replace) ///
lcolor(black) lpattern(dash) lwidth(medthick) msymbol(triangle) mcolor(black) msize(medlarge) title("With {it:Homogenous Ethnic Military}") xtitle("Components") 

graph combine pca1.gph pca2.gph, ycommon xcommon

*****Appendix Table 10*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_leaderid year

eststo: xtreg coup_binary xpers coupyrs coupyrs2 coupyrs3 $dec, cluster(xgwf_leaderid) fe i(xgwf_leaderid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers coupyrs coupyrs2 coupyrs3 $dec, group(xgwf_leaderid) cluster(xgwf_leaderid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3,cluster(xgwf_leaderid)fe i(xgwf_leaderid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3,cluster(xgwf_leaderid) group(xgwf_leaderid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_leaderid)fe i(xgwf_leaderid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_leaderid) group(xgwf_leaderid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable10.tex, b(3) se ar2 

*****Appendix Table 11*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_binary xpers gwf_military coupyrs coupyrs2 coupyrs3 $dec, cluster(xgwf_caseid) i(xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtlogit coup_binary xpers gwf_military coupyrs coupyrs2 coupyrs3 $dec, i(xgwf_caseid) vce(cluster xgwf_caseid) re
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers gwf_military $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) i(xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtlogit coup_binary xpers gwf_military $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3, i(xgwf_caseid) vce(cluster xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers gwf_military $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3, cluster(xgwf_caseid) i(xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtlogit coup_binary xpers gwf_military $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3, i(xgwf_caseid) vce(cluster xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers gwf_military lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3, cluster(xgwf_caseid) i(xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtlogit coup_binary xpers gwf_military lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3, i(xgwf_caseid) vce(cluster xgwf_caseid) re
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable11.tex, b(3) se ar2 

*****Appendix Table 12*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

*paramilitary
eststo: xtreg coup_binary paramil_pers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary paramil_pers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
 tab coup_binary if e(sample)==1

*control
eststo: xtreg coup_binary sectyapp_pers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary sectyapp_pers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
 tab coup_binary if e(sample)==1

*promotion
eststo: xtreg coup_binary milmerit_pers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary milmerit_pers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
 tab coup_binary if e(sample)==1

*purge
eststo: xtreg coup_binary milnotrial $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary milnotrial $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
 tab coup_binary if e(sample)==1

*appointment
eststo: xtreg coup_binary officepers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary officepers $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable12.tex, b(3) se ar2 

*****Appendix Table 13*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_binary xpers leffective coupyrs coupyrs2 coupyrs3 $dec, cluster(xgwf_caseid) fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers leffective coupyrs coupyrs2 coupyrs3 $dec, group(xgwf_caseid) cluster(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers leffective $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers leffective $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers leffective $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers leffective $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  leadermil coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: xtreg coup_binary xpers leffective lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers leffective lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable13.tex, b(3) se ar2 

*****Appendix Table 14*****
*calculate the number of past coups per regime/leader
gen xpt_sumcoup = pt_sumcoup
recode xpt_sumcoup (.=0) /* coup count per year, with missing values as 0 */

gen reg_sumcoup = xpt_sumcoup if xgwf_case_duration==1 | year==1950
xtset xgwf_caseid year
replace reg_sumcoup = xpt_sumcoup + l.reg_sumcoup if l.reg_sumcoup~=.
browse xgwf_casename xgwf_caseid year xpt_sumcoup reg_sumcoup

xtset xgwf_caseid year
gen lreg_sumcoup = l.reg_sumcoup
gen llogreg_sumcoup = log(1+l.reg_sumcoup)

xtset xgwf_leaderid year
gen lldr_sumcoup = l.ldr_sumcoup
gen llogldr_sumcoup = log(1+l.ldr_sumcoup)

recode lreg_sumcoup  (.=0)
recode lldr_sumcoup  (.=0)

*run
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtreg coup_binary xpers $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil i.lldr_sumcoup coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid)fe i(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary xpers $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil i.lldr_sumcoup coupyrs coupyrs2 coupyrs3,cluster(xgwf_caseid) group(xgwf_caseid)
sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable14.tex, b(3) se ar2 

*****Appendix Table 15*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

*if armed group experience = YES
eststo: xtreg coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3 if ldrexp_arm==1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3 if ldrexp_arm==1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
 tab coup_binary if e(sample)==1

*if armed group experience = NO
eststo: xtreg coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3 if ldrexp_arm!=1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3 if ldrexp_arm!=1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

*if armed group experience = YES
eststo: xtreg coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3 if ldroffice_arm==1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV  coupyrs coupyrs2 coupyrs3 if ldroffice_arm==1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
 tab coup_binary if e(sample)==1

*if armed group experience = NO
eststo: xtreg coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3 if ldroffice_arm!=1,cluster(xgwf_caseid)fe i(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

eststo: clogit coup_binary pers4   $dec  lmilexp lmilper milethnic_homo loggdp logoil  ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3 if ldroffice_arm!=1,cluster(xgwf_caseid) group(xgwf_caseid)
 sum year if e(sample)==1
tab coup_binary if e(sample)==1

esttab using AppendixTable15.tex, b(3) se ar2

*****Appendix Figure 13***** (use AVP_base.dta and AVP.do)
*natural death
reg loguntil logtenure loggdp coldwar xpers if exit=="Natural Death", vce(cluster gwf_casename)
avplot pers4, plotregion(lcolor(none) ilcolor(none) style(none)) mcolor(gs10) msize(medsmall) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) scheme(lean2) ylabel(,nogrid) ///
rlopts(lpattern(solid) lcolor(red)) xtitle("e(Personalization index|X)") ytitle("e(Days until coup attempt (logged)|X)") ///
title("Natural death (N=59)") xlabel(-0.6(0.2)0.6) ylabel(-8(4)8) name(av2, replace) 

*foreign
reg loguntil logtenure loggdp coldwar xpers if exit=="Foreign", vce(cluster gwf_casename)
avplot pers4, plotregion(lcolor(none) ilcolor(none) style(none)) mcolor(gs10) msize(medsmall) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) scheme(lean2) ylabel(,nogrid) ///
rlopts(lpattern(solid) lcolor(red)) xtitle("e(Personalization index|X)") ytitle("e(Days until coup attempt (logged)|X)") ///
title("Foreign (N=6)") xlabel(-0.6(0.2)0.6) ylabel(-8(4)8) name(av5, replace) 

*irregular
reg loguntil logtenure loggdp coldwar xpers if exit=="Irregular", vce(cluster gwf_casename)
avplot pers4, plotregion(lcolor(none) ilcolor(none) style(none)) mcolor(gs10) msize(medsmall) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) scheme(lean2) ylabel(,nogrid) ///
rlopts(lpattern(solid) lcolor(red)) xtitle("e(Personalization index|X)") ytitle("e(Days until coup attempt (logged)|X)") ///
title("Irregular (N=118)") xlabel(-0.6(0.2)0.6) ylabel(-8(4)8) name(av3, replace) 

*regular
reg loguntil logtenure loggdp coldwar xpers if exit=="Regular", vce(cluster gwf_casename)
avplot pers4, plotregion(lcolor(none) ilcolor(none) style(none)) mcolor(gs10) msize(medsmall) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) scheme(lean2) ylabel(,nogrid) ///
rlopts(lpattern(solid) lcolor(red)) xtitle("e(Personalization index|X)") ytitle("e(Days until coup attempt (logged)|X)") ///
title("Regular (N=80)") xlabel(-0.6(0.2)0.6) ylabel(-8(4)8) name(av4, replace) 

*illness
reg loguntil logtenure loggdp coldwar xpers if exit=="Retired Due to Ill Health", vce(cluster gwf_casename)
avplot pers4, plotregion(lcolor(none) ilcolor(none) style(none)) mcolor(gs10) msize(medsmall) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) scheme(lean2) ylabel(,nogrid) ///
rlopts(lpattern(solid) lcolor(red)) xtitle("e(Personalization index|X)") ytitle("e(Days until coup attempt (logged)|X)") ///
title("Retired due to illness (N=8)") xlabel(-0.6(0.2)0.6) ylabel(-8(4)8) name(av6, replace) 

graph combine av2 av3 av4 av5 av6, iscale(*.7) col(2) xsize(5) ysize(6)

*****Appendix Figure 14***** (use Instance.dta)
sort duration

sum paramil_pers1 sectyapp_pers1 milmerit_pers1 milnotrial_pers1 officepers1 xpersplus1

line paramil_pers1 duration, sort lwidth(medthick) saving(paramil.gph, replace) scheme(lean2) xlabel(0(10)60,glcolor(gs16)) ///
xtitle("Leader tenure") title("Paramilitary") ytitle("Instance count") ylab(0(25)100,glcolor(gs16)) lpattern(dash) nodraw
line sectyapp_pers1 duration, sort lwidth(medthick) saving(control.gph, replace) scheme(lean2) xlabel(0(10)60,glcolor(gs16)) ///
xtitle("Leader tenure") title("Control") ytitle("Instance count") ylab(0(50)200,glcolor(gs16)) lpattern(dash) nodraw
line milmerit_pers1 duration, sort lwidth(medthick) saving(promotion.gph, replace) scheme(lean2) xlabel(0(10)60,glcolor(gs16)) ///
xtitle("Leader tenure") title("Promotion") ytitle("Instance count") ylab(0(75)300,glcolor(gs16)) lpattern(dash) nodraw
line milnotrial_pers1 duration, sort lwidth(medthick) saving(purge.gph, replace) scheme(lean2) xlabel(0(10)60,glcolor(gs16)) ///
xtitle("Leader tenure") title("Purge") ytitle("Instance count") ylab(0(25)100,glcolor(gs16)) lpattern(dash) nodraw
line officepers1 duration, sort lwidth(medthick) saving(appointment.gph, replace) scheme(lean2) xlabel(0(10)60,glcolor(gs16)) ///
xtitle("Leader tenure") title("Appointment") ytitle("Instance count") ylab(0(50)200,glcolor(gs16)) lpattern(dash) nodraw
line xpersplus1 duration, sort lwidth(medthick) saving(index.gph, replace) scheme(lean2) xlabel(0(10)60,glcolor(gs16)) ///
xtitle("Leader tenure") title("Increase in Personalization Level") ytitle("Instance count") ylab(0(15)60,glcolor(gs16)) lpattern(dash) nodraw

graph combine paramil.gph control.gph promotion.gph purge.gph appointment.gph index.gph ///
,col(2) iscale(*.7) xsize(10) ysize(10) scheme(lean2) xcommon

*****Appendix Figure 15*****
*gsem IRT to construct gsem.dta
quietly: gsem (IRT4 -> officepers milmerit_pers milnotrial paramil_pers), logit var(IRT4@1)
estat ic
quietly: gsem (IRT5 -> officepers milmerit_pers milnotrial paramil_pers sectyapp_pers), logit var(IRT5@1)
estat ic
quietly: gsem (IRT6homo -> officepers milmerit_pers milnotrial paramil_pers sectyapp_pers milethnic_homo), logit var(IRT6homo@1)
estat ic
quietly: gsem (IRT6exc -> officepers milmerit_pers milnotrial paramil_pers sectyapp_pers milethnic_exclusive), logit var(IRT6exc@1)
estat ic
quietly: gsem (IRT6EPR -> officepers milmerit_pers milnotrial paramil_pers sectyapp_pers lEPR), logit var(IRT6EPR@1)
estat ic
quietly: gsem (IRT6counter -> officepers milmerit_pers milnotrial paramil_pers sectyapp_pers lcw), logit var(IRT6counter@1)
estat ic

*use gsem.dta
replace AIC = -AIC
graph hbar (asis) AIC BIC if order!=., over(model, sort(order) label(labsize(small))) ///
scheme(lean2) ylab(,labsize(small) nogrid) blabel(total, size(vsmall)) ///
legend(position(6) col(2) order(1 "Akaike information criterion" 2 "Bayesian information criterion") size(small)) ///
note("Smaller is considered better.",span) 

*****Appendix Figure 16*****
*IRT with milethnic_exclusive
irt 2pl officepers milmerit_pers sectyapp_pers milnotrial paramil_pers milethnic_exclusive
estat report, byparm sort(a)
/*
-------------------------------------------------------------------------------------
                    |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
--------------------+----------------------------------------------------------------
Discrim             |
milethnic_exclusive |   .4666266   .0395215    11.81   0.000     .3891658    .5440874
         milnotrial |   1.318337   .0656802    20.07   0.000     1.189606    1.447067
      milmerit_pers |   1.436587   .0743941    19.31   0.000     1.290777    1.582396
         officepers |   1.729643   .0803321    21.53   0.000     1.572195    1.887091
       paramil_pers |   2.030095   .1047637    19.38   0.000     1.824762    2.235428
      sectyapp_pers |   3.327007   .2287897    14.54   0.000     2.878588    3.775427
--------------------+----------------------------------------------------------------
Diff                |
milethnic_exclusive |  -.4038381   .0745712    -5.42   0.000     -.549995   -.2576812
         milnotrial |   .5585004   .0353419    15.80   0.000     .4892317    .6277692
      milmerit_pers |  -1.108376   .0462963   -23.94   0.000    -1.199115   -1.017637
         officepers |  -.5258024   .0297182   -17.69   0.000    -.5840491   -.4675557
       paramil_pers |   .4892446   .0273219    17.91   0.000     .4356946    .5427947
      sectyapp_pers |  -.2896546   .0219469   -13.20   0.000    -.3326697   -.2466395
-------------------------------------------------------------------------------------
*/
irtgraph icc (paramil_pers, lcolor(green)) (sectyapp_pers, lcolor(red)) (milmerit_pers, lcolor(gold) blocation(lcolor(gold) lwidth(vthin) lpattern(solid))) ///
(milnotrial, lcolor(gray) blocation(lcolor(gray) lwidth(vthin) lpattern(solid))) (officepers, lcolor(blue)) (milethnic_exclusive, lcolor(black) lpattern(dash)), ///
legend(col(2) size(small) position(6) ///
order(1 "Personal paramilitary" 2 "Personal control" 3 "Personal promotion" 4 "Personal purge" 5 "Personal appointment" 6 "GWF ethnic exclusion")) ///
subtitle("GWF ethnic exclusion in military") xsize(6) ysize(5) scheme(lean2) ///
ylabel(0(0.25)1,nogrid) yline(0.5, lpattern(solid) lcolor(gs12) lwidth(vthin)) xtitle("Difficulty") ///
name(iccExclusive, replace) 

*IRT with EPR
irt 2pl officepers milmerit_pers sectyapp_pers milnotrial paramil_pers lEPR
estat report, byparm sort(a)
/*
Two-parameter logistic model                    Number of obs     =      4,457
Log likelihood = -15018.509
-------------------------------------------------------------------------------
              |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
Discrim       |
         lEPR |  -.2523593   .0421216    -5.99   0.000    -.3349162   -.1698024
   milnotrial |   1.377054     .06884    20.00   0.000      1.24213    1.511978
milmerit_pers |   1.418498   .0740286    19.16   0.000     1.273405    1.563591
   officepers |   1.755207    .082216    21.35   0.000     1.594066    1.916347
 paramil_pers |   1.873141   .0943919    19.84   0.000     1.688136    2.058146
sectyapp_pers |   3.529294   .2675208    13.19   0.000     3.004962    4.053625
--------------+----------------------------------------------------------------
Diff          |
         lEPR |   3.442062   .5700364     6.04   0.000     2.324812    4.559313
   milnotrial |   .5441172   .0342839    15.87   0.000      .476922    .6113123
milmerit_pers |  -1.115945   .0470155   -23.74   0.000    -1.208093   -1.023796
   officepers |  -.5227536   .0294398   -17.76   0.000    -.5804546   -.4650527
 paramil_pers |     .50449   .0285171    17.69   0.000     .4485975    .5603826
sectyapp_pers |  -.2878729   .0216185   -13.32   0.000    -.3302444   -.2455014
-------------------------------------------------------------------------------
*/
irtgraph icc (paramil_pers, lcolor(green)) (sectyapp_pers, lcolor(red)) (milmerit_pers, lcolor(gold) blocation(lcolor(gold) lwidth(vthin) lpattern(solid))) ///
(milnotrial, lcolor(gray)) (officepers, lcolor(blue)) (lEPR, lcolor(black) lpattern(dash) blocation(lcolor(black) lwidth(vthin) lpattern(solid))), ///
legend(col(2) size(vsmall) position(6) ///
order(1 "Personal paramilitary" 2 "Personal control" 3 "Personal promotion" 4 "Personal purge" 5 "Personal appointment" 6 "EPR ethnic exclusion")) ///
subtitle("EPR ethnic exclusion in politics")  xsize(6) ysize(5) scheme(lean2) ///
ylabel(0(0.25)1,nogrid) yline(0.5, lpattern(solid) lcolor(gs12) lwidth(vthin)) xtitle("Difficulty") ///
name(iccEPR, replace) 

graph combine iccExclusive iccEPR, col(2) xsize(10) ysize(6)

*****Appendix Figure 17*****
*GRM IRT with cbcount
irt grm officepers milmerit_pers sectyapp_pers milnotrial paramil_pers lcw
estat report, byparm sort(a)
/*
----------------------------------------------------------------------------------
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-----------------+----------------------------------------------------------------
         Discrim |
        cbcount  |   .5886926   .0516887    11.39   0.000     .4873846    .6900007
     milnotrial  |   1.298869   .0650647    19.96   0.000     1.171345    1.426393
  milmerit_pers  |    1.36985   .0707616    19.36   0.000      1.23116     1.50854
     officepers  |   1.712377   .0789678    21.68   0.000     1.557603    1.867151
   paramil_pers  |   2.035076    .104783    19.42   0.000     1.829705    2.240447
  sectyapp_pers  |   3.570478   .2667446    13.39   0.000     3.047668    4.093287
            Diff |
     cbcount>=1  |  -1.483599   .1437222   -10.32   0.000    -1.765289   -1.201909
     cbcount>=2  |   .8739623   .1082624     8.07   0.000     .6617718    1.086153
     cbcount>=3  |   3.698428   .3162471    11.69   0.000     3.078595    4.318261
     cbcount>=4  |    6.63663   .5970352    11.12   0.000     5.466463    7.806797
     cbcount>=6  |   9.300434   .9436862     9.86   0.000     7.450843    11.15003
     cbcount>=7  |   10.48163   1.162126     9.02   0.000     8.203904    12.75936
     cbcount>=8  |   11.35086   1.369366     8.29   0.000     8.666952    14.03477
      cbcount=9  |   12.04037   1.573319     7.65   0.000      8.95672    15.12402
   milnotrial=1  |   .5646253   .0357381    15.80   0.000       .49458    .6346707
milmerit_pers=1  |  -1.137995   .0484495   -23.49   0.000    -1.232954   -1.043035
   officepers=1  |  -.5268555   .0298937   -17.62   0.000    -.5854461    -.468265
 paramil_pers=1  |   .4905108   .0272497    18.00   0.000     .4371024    .5439192
sectyapp_pers=1  |  -.2830865    .021619   -13.09   0.000    -.3254589   -.2407141
----------------------------------------------------------------------------------
*/
irtgraph iif (paramil_pers, lcolor(green)) (sectyapp_pers, lcolor(red)) (milmerit_pers, lcolor(gold)) ///
(milnotrial, lcolor(gray)) (officepers, lcolor(blue)) (lcw, lcolor(black) lpattern(dash)), ///
legend(col(2) size(small) position(6) ///
order(1 "Personal paramilitary" 2 "Personal control" 3 "Personal promotion" 4 "Personal purge" 5 "Personal appointment" 6 "Counterweight count")) ///
xsize(6) ysize(5) scheme(lean2) ylabel(,nogrid) xtitle("Difficulty") subtitle("Number of counterweights") ///
name(counterCount, replace) 

*IRT with lcw2
irt 2pl officepers milmerit_pers sectyapp_pers milnotrial paramil_pers lcw2
estat report, byparm sort(a)
/*
-------------------------------------------------------------------------------
              |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
Discrim       |
         lcw2 |   .1885701   .0537628     3.51   0.000      .083197    .2939432
   milnotrial |   1.347761   .0675802    19.94   0.000     1.215307    1.480216
milmerit_pers |    1.42622   .0741123    19.24   0.000     1.280962    1.571477
   officepers |    1.73499   .0810766    21.40   0.000     1.576083    1.893897
 paramil_pers |   1.957368   .0999053    19.59   0.000     1.761558    2.153179
sectyapp_pers |   3.431379   .2488611    13.79   0.000      2.94362    3.919138
--------------+----------------------------------------------------------------
Diff          |
         lcw2 |  -10.09089   2.847739    -3.54   0.000    -15.67235   -4.509422
   milnotrial |   .5516869   .0348119    15.85   0.000     .4834568    .6199169
milmerit_pers |  -1.112325   .0467196   -23.81   0.000    -1.203893   -1.020756
   officepers |  -.5245424   .0296845   -17.67   0.000     -.582723   -.4663618
 paramil_pers |   .4965854   .0278422    17.84   0.000     .4420157    .5511551
sectyapp_pers |  -.2875155   .0217966   -13.19   0.000    -.3302361    -.244795
-------------------------------------------------------------------------------
*/
irtgraph icc (paramil_pers, lcolor(green)) (sectyapp_pers, lcolor(red)) (milmerit_pers, lcolor(gold)) ///
(milnotrial, lcolor(gray) blocation(lcolor(gray) lwidth(vthin) lpattern(solid))) ///
(officepers, lcolor(blue)) (lcw2, lcolor(black) lpattern(dash) blocation(lcolor(black) lwidth(vthin) lpattern(solid))), ///
legend(col(2) size(small) position(6) ///
order(1 "Personal paramilitary" 2 "Personal control" 3 "Personal promotion" 4 "Personal purge" 5 "Personal appointment" 6 "Binary counterweight")) ///
xsize(6) ysize(5) scheme(lean2) ylabel(0(0.25)1,nogrid) yline(0.5, lpattern(solid) lcolor(gs12) lwidth(vthin)) xtitle("Difficulty") subtitle("Binary counterweight") ///
name(counterBinary, replace) 

graph combine counterCount counterBinary, col(2) xsize(10) ysize(6)

*****Appendix Table 16*****
global dec ="d196 d197 d198 d199 d200"

eststo clear
tsset xgwf_caseid year

eststo: xtnbreg coupsum pers4 coupyrs coupyrs2 coupyrs3 $dec, fe i(xgwf_caseid) 
sum year if e(sample)==1
tab coupsum if e(sample)==1

eststo: xtreg logcoupsum pers4 coupyrs coupyrs2 coupyrs3 $dec, cluster(xgwf_caseid) fe i(xgwf_caseid)
sum year if e(sample)==1
tab logcoupsum if e(sample)==1

eststo: xtnbreg coupsum pers4 $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3, fe i(xgwf_caseid) 
sum year if e(sample)==1
tab coupsum if e(sample)==1

eststo: xtreg logcoupsum pers4 $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV coupyrs coupyrs2 coupyrs3, cluster(xgwf_caseid) fe i(xgwf_caseid)
sum year if e(sample)==1
tab logcoupsum if e(sample)==1

eststo: xtnbreg coupsum pers4 $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3, fe i(xgwf_caseid) 
sum year if e(sample)==1
tab coupsum if e(sample)==1

eststo: xtreg logcoupsum pers4 $dec lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coupyrs coupyrs2 coupyrs3, cluster(xgwf_caseid) fe i(xgwf_caseid)
sum year if e(sample)==1
tab logcoupsum if e(sample)==1

eststo: xtnbreg coupsum pers4 lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3, fe i(xgwf_caseid) 
sum year if e(sample)==1
tab coupsum if e(sample)==1

eststo: xtreg logcoupsum pers4 lmilexp lmilper milethnic_homo loggdp logoil ucdp25 ucdp1000 lnavcoV lnavcoNV leadermil coldwar coupyrs coupyrs2 coupyrs3, cluster(xgwf_caseid) fe i(xgwf_caseid)
sum year if e(sample)==1
tab logcoupsum if e(sample)==1

esttab using AppendixTable16.tex, b(3) se ar2 



















